<?php
namespace app\controllers;

use app\logic\AreaLogic;
use app\models\Area;
use Yii;

class AreaController extends BackendController
{

/*	public function actionIndex()
	{
        $areaLogic=new AreaLogic();
        $query = Yii::$app->request->get('form', []);
        $page = Yii::$app->request->get('page', 1);
        $this->data['breadcrumbs'] = '区域管理';
        return $this->render('index', [
            'data' => $areaLogic->getAreaList($query, $page),
            'query' => $query
        ]);
	}*/
    public function actionIndex()
	{
        $areaLogic = new AreaLogic();
        $province = $areaLogic->getProvince();
//        $city = $areaLogic->getCity();
//        $district = $areaLogic->getDistrict();
//        $street = $areaLogic->getStreet();
        return $this->render('index',['data' => [
            'province'=>$province,
            //'city'=>$city,
            //'district'=>$district,
            //'street'=>$street
        ]]);
	}

    public function actionGetzone(){
        $id = Yii::$app->request->post('zoneid');
        if($id!=0){
            $regions = Area::find()->where(['parent_code'=>$id])->asArray()->all();
        }else{
            $regions[0]['region_code'] = '0';
            $regions[0]['region_name'] = "全部";
        }
        //$region = Region::findOne(['region_code'=>$id]);

        echo json_encode($regions);
    }

    public function actionGetzone1(){
        $id = Yii::$app->request->post('zoneid');
        //$region = Region::findOne(['region_code'=>$id]);
        $region = Area::find()->where(['region_code'=>$id])->asArray()->one();
        echo json_encode($region);
    }



    public function actionError()
	{
        return $this->render('error');
	}
    


}